/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eproject_sem2;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author ZER0
 */
@SuppressWarnings("serial")
public class Edit_Password extends javax.swing.JFrame {

    Edit_Passwrod_Sever s = new Edit_Passwrod_Sever();

    public JInternalFrame getjInternalFrame1() {
        return itnfUpdatePass;
    }
    

    /**
     * Creates new form Edit_Password
     */
    public Edit_Password() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        itnfUpdatePass = new javax.swing.JInternalFrame();
        jpUpdatePass = new javax.swing.JPanel();
        lbUserU = new javax.swing.JLabel();
        tfUserID = new javax.swing.JTextField();
        lbUserNameU = new javax.swing.JLabel();
        tfUserNameU = new javax.swing.JTextField();
        lbPasswordOldU = new javax.swing.JLabel();
        pfPassOldU = new javax.swing.JPasswordField();
        pfNewPassU = new javax.swing.JPasswordField();
        lbNewPasU = new javax.swing.JLabel();
        lbENewPass = new javax.swing.JLabel();
        pfENewPass = new javax.swing.JPasswordField();
        btUpdatepassU = new javax.swing.JButton();
        btCancelPU = new javax.swing.JButton();
        btResetPU = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        itnfUpdatePass.setClosable(true);
        itnfUpdatePass.setVisible(true);

        jpUpdatePass.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Update_Password", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        lbUserU.setText("UserID:");

        lbUserNameU.setText("User name:");

        lbPasswordOldU.setText("Password old:");

        pfNewPassU.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pfNewPassUActionPerformed(evt);
            }
        });

        lbNewPasU.setText("New password:");

        lbENewPass.setText("E new password:");

        btUpdatepassU.setText("Update");
        btUpdatepassU.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btUpdatepassUActionPerformed(evt);
            }
        });

        btCancelPU.setText("Cancel");
        btCancelPU.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelPUActionPerformed(evt);
            }
        });

        btResetPU.setText("Reset");
        btResetPU.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btResetPUActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpUpdatePassLayout = new javax.swing.GroupLayout(jpUpdatePass);
        jpUpdatePass.setLayout(jpUpdatePassLayout);
        jpUpdatePassLayout.setHorizontalGroup(
            jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpUpdatePassLayout.createSequentialGroup()
                .addGroup(jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpUpdatePassLayout.createSequentialGroup()
                        .addGap(254, 254, 254)
                        .addComponent(btUpdatepassU, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btResetPU)
                        .addGap(18, 18, 18)
                        .addComponent(btCancelPU))
                    .addGroup(jpUpdatePassLayout.createSequentialGroup()
                        .addGap(144, 144, 144)
                        .addGroup(jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbENewPass)
                            .addComponent(lbUserU)
                            .addComponent(lbUserNameU)
                            .addComponent(lbPasswordOldU)
                            .addComponent(lbNewPasU))
                        .addGap(30, 30, 30)
                        .addGroup(jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(tfUserID, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(tfUserNameU, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(pfPassOldU, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(pfENewPass, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(pfNewPassU, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(160, Short.MAX_VALUE))
        );
        jpUpdatePassLayout.setVerticalGroup(
            jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpUpdatePassLayout.createSequentialGroup()
                .addGap(74, 74, 74)
                .addGroup(jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfUserID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbUserU, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfUserNameU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbUserNameU))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbPasswordOldU)
                    .addComponent(pfPassOldU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbNewPasU)
                    .addComponent(pfENewPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbENewPass)
                    .addComponent(pfNewPassU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(108, 108, 108)
                .addGroup(jpUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btUpdatepassU)
                    .addComponent(btResetPU)
                    .addComponent(btCancelPU))
                .addGap(79, 79, 79))
        );

        javax.swing.GroupLayout itnfUpdatePassLayout = new javax.swing.GroupLayout(itnfUpdatePass.getContentPane());
        itnfUpdatePass.getContentPane().setLayout(itnfUpdatePassLayout);
        itnfUpdatePassLayout.setHorizontalGroup(
            itnfUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(itnfUpdatePassLayout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addComponent(jpUpdatePass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(64, Short.MAX_VALUE))
        );
        itnfUpdatePassLayout.setVerticalGroup(
            itnfUpdatePassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(itnfUpdatePassLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpUpdatePass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(36, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfUpdatePass)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfUpdatePass, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btUpdatepassUActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btUpdatepassUActionPerformed
        try {
            // TODO add your handling code here:
            String p1 = MH_MD5.MD5(pfPassOldU.getText());
            if (s.CheckUSer(tfUserNameU.getText(), p1) != null) {
                String Pass = MH_MD5.MD5(pfNewPassU.getText());
                if (pfNewPassU.getText().equalsIgnoreCase(pfENewPass.getText())) {
                    if (s.UpdatePrice(tfUserID.getText(), tfUserNameU.getText(), Pass, "Users", "UserID", "Username", "Password") != false) {
                        JOptionPane.showMessageDialog(this, "Update pass");
                    }
                }
            } else {
                JOptionPane.showMessageDialog(this, "Information account that is not true,you can check again");
            }
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Edit_Password.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Edit_Password.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btUpdatepassUActionPerformed

    private void btResetPUActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btResetPUActionPerformed
        // TODO add your handling code here:
        tfUserID.setText(null);
        tfUserNameU.setText(null);
        pfENewPass.setText(null);
        pfNewPassU.setText(null);
        pfPassOldU.setText(null);
    }//GEN-LAST:event_btResetPUActionPerformed

    private void btCancelPUActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelPUActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_btCancelPUActionPerformed

    private void pfNewPassUActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pfNewPassUActionPerformed
        // TODO add your handling code here:
        try {
            // TODO add your handling code here:
            String p1 = MH_MD5.MD5(pfPassOldU.getText());
            if (s.CheckUSer(tfUserNameU.getText(), p1) != null) {
                String Pass = MH_MD5.MD5(pfNewPassU.getText());
                if (pfNewPassU.getText().equalsIgnoreCase(pfENewPass.getText())) {
                    if (s.UpdatePrice(tfUserID.getText(), tfUserNameU.getText(), Pass, "Users", "UserID", "Username", "Password") != false) {
                        JOptionPane.showMessageDialog(this, "Update pass");
                    }
                }
            } else {
                JOptionPane.showMessageDialog(this, "Information account that is not true,you can check again");
            }
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Edit_Password.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Edit_Password.class.getName()).log(Level.SEVERE, null, ex);
     
        }
        
    }//GEN-LAST:event_pfNewPassUActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelPU;
    private javax.swing.JButton btResetPU;
    private javax.swing.JButton btUpdatepassU;
    private javax.swing.JInternalFrame itnfUpdatePass;
    private javax.swing.JPanel jpUpdatePass;
    private javax.swing.JLabel lbENewPass;
    private javax.swing.JLabel lbNewPasU;
    private javax.swing.JLabel lbPasswordOldU;
    private javax.swing.JLabel lbUserNameU;
    private javax.swing.JLabel lbUserU;
    private javax.swing.JPasswordField pfENewPass;
    private javax.swing.JPasswordField pfNewPassU;
    private javax.swing.JPasswordField pfPassOldU;
    private javax.swing.JTextField tfUserID;
    private javax.swing.JTextField tfUserNameU;
    // End of variables declaration//GEN-END:variables
}
